import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-goods/'

/**
 * 对某个订单进行发货
 * @param {Array<DeliverGoodDTO>} deliverGoodList 发货相关信息，包括物流信息
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const deliverGoodByOrderIds = (deliverGoodList, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_deliver/deliverGoodByOrderIds', deliverGoodList, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 修改发货后的订单发货信息
 * @param {Array<DeliverGoodChangeDTO>} deliverGoodChangeList 发货相关信息，包括物流信息
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const changeDeliverGoodByOrderIds = (deliverGoodChangeList, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_deliver/changeDeliverGoodByOrderIds', deliverGoodChangeList, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 根据订单id取消发货信息
 * @param {Array<String|Number>} orderIds 订单id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const cancelDeliverByOrderIds = (orderIds, successCallback = null, fullCallback = null) => {
  return fallbackRequestPost(URL_PREFIX + 'good_deliver/cancelDeliverByOrderIds', orderIds, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 物流订单号识别
 * @param {Number|String} code 物流订单号
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const orderDistinguish = (code, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_deliver/orderDistinguish', { code }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}

/**
 * 商铺用户调用，根据订单号查询物流信息
 * @param {Number|String} orderId 物流订单号
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryTranceByOrderIdStore = (orderId, successCallback = null, fullCallback = null) => {
  return fallbackRequestGet(URL_PREFIX + 'good_deliver/queryTranceByOrderIdStore', { orderId }, {}, true, data => {
    if (successCallback) {
      successCallback(data)
    }
  }, null, fullCallback)
}
